package com.ckerchina.admin.ckadmin.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.ckerchina.admin.ckadmin.domain.mgr.MgrUser;

@Repository
public class MgrUserDAO extends AbstractDao<MgrUser, Long>{
	public MgrUser findByName(String username) { 
		List<MgrUser> list = this.entityManager
				.createQuery("SELECT o FROM MgrUser o WHERE o.name = ?", MgrUser.class)
				.setParameter(1, username).getResultList();
		return list.size() > 0 ? list.get(0) : null;
	}
	
	@SuppressWarnings("unchecked")
	public List<MgrUser> findAllMgrUser() {
		String sql = "SELECT m.id,m.actortype,m.companyid,a.agent_name as companyname,m.create_time,m.email,m.`name`,m.pwd,m.realname,m.state FROM mgr_user m LEFT OUTER JOIN agent_user a ON m.companyid = a.id";
		return this.entityManager.createNativeQuery(sql, MgrUser.class).getResultList();
//		return this.entityManager.createQuery("SELECT o FROM MgrMenu o ORDER BY o.sortNo ASC", MgrMenu.class)
//				.getResultList();
		
	}
}
